<template>
  <div id="addUserContainer">
    <el-form label-width="120px" size="large">
      <el-form-item label="用户姓名">
        <el-input type="text" v-model="user.userName"/>
      </el-form-item>
      <el-form-item label="联系邮箱">
        <el-input type="text" v-model="user.userEmail"/>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="user.userSex">
          <el-radio :label="1">男</el-radio>
          <el-radio :label="2">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="生日">
        <el-date-picker value-format="YYYY-MM-DD" type="date" v-model="user.userBirthday"/>
      </el-form-item>
      <el-form-item label="身份">
        <el-select v-model="user.userType">
          <el-option :value="1" label="用户"/>
          <el-option :value="2" label="管理员"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="doRegister">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "AddUser",
  data() {
    return {
      user: {
        userName: '',
        userEmail: '',
        userSex: 1,
        userBirthday: '',
        userType: 1
      }
    }
  },
  methods: {
    doRegister() {
      this.$axios.put('/user-info', this.user).then(({data: res}) => {
        if (res.code === 0 && res.data > 0) {
          this.$message.success("添加成功");
          this.$router.push('/users');
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
  #addUserContainer {
    width: 600px;
    margin-top: 30px;
  }
</style>
